package com.ceadeal.auth.web;

import com.ceadeal.auth.util.OAuth2Util;
import com.ceadeal.auth.entity.User;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 描述：oauth2
 * @param
 * @return
 * @throws
 *
 * @author Westin Yang
 * @date 2017-03-30 01:13:47
 */
@Controller
@RestController
public class UserController {

    private static Logger LOGGER = LoggerFactory.getLogger(UserController.class);

    @RequestMapping("/user")
    public Map<String, Object> user() {
        User user = OAuth2Util.getUser();
        ObjectMapper om = new ObjectMapper();
        String json = null;
        try {
            json = (user == null ? null : om.writeValueAsString(user));
        } catch (JsonProcessingException e) {
            LOGGER.error("ERROR：", e);
        }
        Map<String, Object> result = new HashMap<>();
        result.put("user", json);
        return result;
    }

}
